<template>
	<view class="page" v-if="checkPermission(['ROOT', 'MEETING:APPROVAL'])">
		<view class="meeting">
			<view class="header">{{ title }}</view>
			<view class="attr">
				<view class="list">
					<view class="item">
						<view class="key">日期</view>
						<text class="value">{{ date }}</text>
					</view>
					<view class="item">
						<view class="key">开始时间</view>
						<text class="value">{{ start }}</text>
					</view>
					<view class="item">
						<view class="key">结束时间</view>
						<text class="value">{{ end }}</text>
					</view>
					<view class="item">
						<view class="key">会议类型</view>
						<text class="value">{{ typeArray[typeIndex] }}</text>
					</view>
					<view class="item" v-if="typeArray[typeIndex] == '线下会议'">
						<view class="key">地点</view>
						<view class="value">{{ place }}</view>
					</view>
				</view>
				<view>
					<text class="desc">{{ desc }}</text>
				</view>
			</view>
			<view class="members">
				<view class="number">参会者（{{ members.length }}人）</view>
				<view class="member">
					<view class="user" v-for="one in members" :key="one.id">
						<image :src="one.photo" mode="widthFix" class="photo"></image>
						<text class="name">{{ one.name }}</text>
					</view>
				</view>
			</view>
			<block v-if="status == 1">
				<button class="btn" @tap="approvalMeeting('同意')" type="primary">同意</button>
				<button class="btn" @tap="approvalMeeting('不同意')" type="warn">不同意</button>
			</block>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			processType: null,
			taskId: null,
			id: null,
			uuid: null,
			title: '',
			date: '',
			start: '',
			end: '',
			typeArray: ['在线会议', '线下会议'],
			typeIndex: 0,
			place: '',
			desc: '',
			members: [],
			status: 0
		};
	},
	onLoad: function(options) {
		this.id = options.id;
	},
	onShow: function() {
		let that = this;
		that.ajax(that.url.searchMeetingById, 'POST', { id: that.id }, function(resp) {
			let result = resp.data.result;
			console.log(result);
			that.uuid = result.uuid;
			that.title = result.title;
			that.date = result.date;
			that.start = result.start;
			that.end = result.end;
			that.typeIndex = result.type - 1;
			that.place = result.place;
			that.status = result.status;
			let desc = result.desc;
			if (desc != null && desc != '') {
				that.desc = desc;
			}
			that.members = result.members;
		});
	},
	methods: {
		approvalMeeting(approval) {
			let that = this;
			uni.showModal({
				title: '提示信息',
				content: '你' + approval + '这条申请？',
				success: function(resp) {
					if (resp.confirm) {
						
						if(approval=='同意'){
							that.status=3
						}else if(approval=='不同意'){
							that.status=2
						}
						
						let array = [];
						for (let one of that.members) {
							array.push(one.id);
						}
						
						let data = {
							title: that.title,
							date: that.date,
							place: that.place,
							start: that.start,
							title: that.title,
							end: that.end,
							desc: that.desc,
							id: that.id,
							status: that.status,
							type: that.typeIndex+1,
							members:JSON.stringify(array)
						};
						
						that.ajax(that.url.updateMeetingInfo, 'POST', data, function(resp) {
							uni.showToast({
								icon: 'success',
								title: '处理完成',
								complete: function() {
									setTimeout(function() {
										uni.navigateBack({});
									}, 2000);
								}
							});
						});
					}
				}
			});
		}
	}
};
</script>

<style lang="less">
@import url('approval.less');
</style>
